import json

from flask import Blueprint
from flask import render_template
from flask import request

from src.controllers.auth_controller import login_verification

bp = Blueprint("blog", __name__, url_prefix="/blog", template_folder="templates", static_folder="static")


def index():
    posts = [1, 2, 3]
    return render_template("/blog/index.html", posts=posts)


@bp.route("/create", methods=["GET", "POST"])
@login_verification
def create():
    if request.method == "POST":
        data = request.data.decode("utf-8")
        data = json.loads(data)
        data.update({"msg": "200 ok"})
        return data
    return render_template("/blog/edit.html")